<?php
// 本类由系统自动生成，仅供测试用途
class BackstageAction extends Action {
    public function admin(){
    		$this->display();
	}
	
	//添加商品信息
	public function addGoods(){
		$data['name']=I('name');
		$data['style'] = I('clothesStyle');
		$data['style'] = I('clothesStyle');
		$data['color'] = I('color'); 
		$data['color_img'] = I('colorImg'); 
		$data['size'] = I('size'); 
		$data['repertory'] = I('repertory'); 
		$data['n_price'] = I('nowPrice'); 
		$data['b_price'] = I('beforePrice'); 
		$data['attribute'] = I('attribute'); 
		$data['small_img'] = I('smallImg'); 
		$data['show_img'] = I('showImg');
		$detail = M("detail");
		$res = $detail->add($data); 
		if($res){
			$this->ajaxReturn("","",1);
		}else{
			$this->ajaxReturn("","",0);
		}  
	}
	
	//获取商品信息
	public function showGoods(){
		$detail = M('detail');
		import('ORG.Util.Page');//导入分页类
		$count = $detail->count();//查询满足条件的数组条数
		$page = new Page($count,6);//实例化分页类 传入总记录数
		$show = $page->show();//分页输出显示
		$list = $detail->order('id DESC')->page($_GET['p'].',6')->select();
		foreach($list as $key => $value){
			if(strpos($list[$key]['color_img'],',')){
				$list[$key]['color_img'] = explode(',',$list[$key]['color_img'],-1)[0];
			}	
		}
		$this->assign('page',$show);
		$this->assign("goodslist",$list);
		$this->display("admin");
	} 
	
	//修改商品信息
	public function changeGoods(){
		
		$id = I('id');
		$data['name']=I('name');
		$data['n_price'] = I('n_price');
		$data['color'] = I('color');
		$data['size'] = I('size');
		$data['style'] = I('clothesStyle');
		$detail = M("detail");
		$where['id'] = $id;
		$change = $detail->where($where)->save($data);
		if($change){
			$this->ajaxReturn($data,"",1);
		}else{
			$this->ajaxReturn($data,"",0);
		}  
		
	}
	
	//删除商品
	public function deleteGoods(){
		$id=I('id');
		$detail = M("detail");
		$where['id'] = $id; 
		$detele=$detail->where($where)->delete();
		if($detele){
			$this->ajaxReturn("","",1);
		}else{
			$this->ajaxReturn("","",0);
		}  
	}

	public function orders(){
        $orders = M('order_list');
        if(!empty(I('search'))){
            $where['orderNumber'] = I('search');
            $list = $orders->where($where)->order('id DESC')->select();
        }else{
            $list = $orders->order('id DESC')->select();
//        echo "<pre>";
//        var_dump($list);die;
        }
        $this->assign('orders',$list);
        $this->display('admin');
    }
    //修改订单
    public function ordersDeal(){
        I('orderStatus');
        $orders = M('order_list');
        $where['id'] = I('id');;
        $data['status'] = I('orderStatus');
        $one = $orders->where($where)->save($data);
        $this->ajaxReturn($one);
        if($one){
            $this->ajaxReturn('','',1);
        }else{
            $this->ajaxReturn('','',0);
        }
    }
}